import $util from "@/utils/index.js"
import $api from "@/api/index.js"
export default {
	state: {
		pageActive: false,
		haveOperItem: false,
		param: {
			page: 1,
			lat: 0,
			lng: 0,
			title: '',
			type_id: 0,
			time: 0, // 0全部 1今天 2明天 3三天 4本周 5本月
			money_type: 0 //0全部 1免费2请客3aa
		},
		list: {
			data: [],
			last_page: 1,
			current_page: 1
		},
		cateList:[],
		tabList: [{
			id: 1,
			title: '月份选择'
		}, {
			id: 2,
			title: '自定义时间'
		},{
			id: 3,
			title: '月份选择'
		}, {
			id: 4,
			title: '自定义时间'
		}],
		activeIndex: 0,
		timeList: [
			{title: '不限', id: 0},
			{title: '今天', id: 1},
			{title: '明天', id: 2},
			{title: '三天内', id: 3},
			{title: '一周内', id: 4},
			{title: '一月内', id: 5}
		],
		moneyTypeList: [
			{title: '不限', id: 0},
			{title: '免费', id: 1},
			{title: '局主请客', id: 2},
			{title: 'AA组局', id: 3},
		],
		check: {
			time: 0,
			money_type: 0
		}
	},
	mutations: {
		async updatePartnerItem(state, item) {
			let {
				key,
				val
			} = item
			state[key] = val
		}
	},
	actions: {
		async getTypeList({
			commit,
			state
		}, param) {
			let d = await $api.partner.typeList(param) 
			let isDel = false
			d.forEach(item=>{
				item.title = item.name
				if(item.id == state.param.type_id){
					isDel = true
				}
			})
			if(!isDel){
				state.param.type_id = 0
				state.activeIndex = 0
			}
			d.unshift({
				title: '全部',
				id: 0
			})
			
			commit('updatePartnerItem', {
				key: 'cateList',
				val: d
			})
		},
		async getPartnerList({
			commit,
			state
		}, param) {
			let d = await $api.partner.getPartnerList(param)
			let oldList = state.list;
			let newList = d;
			let list = {}
			if (param.page == 1) {
				list = newList;
			} else {
				newList.data = oldList.data.concat(newList.data)
				list = newList;
			}
			commit('updatePartnerItem', {
				key: 'param',
				val: param
			})
			commit('updatePartnerItem', {
				key: 'list',
				val: list
			})
		}
	},
}
